package com.loongxun.playwithyou.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.loongxun.playwithyou.R;
import com.loongxun.playwithyou.bean.BillStatis;
import com.loongxun.playwithyou.ui.activity.playuser.BillInfoListActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/7/20.
 */
public class BillAdapter extends BaseAdapter {

    private Context context;
    public List<BillStatis> list;
    private LayoutInflater inflater;

    public void setList(List<BillStatis> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public BillAdapter(Context context, List<BillStatis> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if(convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_order_member, null);

            holder.ll_item_order_list = (LinearLayout) convertView.findViewById(R.id.ll_item_order_list);
            holder.item_order_list_orderno = (TextView) convertView.findViewById(R.id.item_order_list_orderno);
            holder.item_order_list_orderdate = (TextView) convertView.findViewById(R.id.item_order_list_orderdate);
            holder.item_order_list_cycle = (TextView) convertView.findViewById(R.id.item_order_list_cycle);
            holder.item_order_list_cycle.setVisibility(View.VISIBLE);
            holder.item_order_list_hoursnum = (TextView) convertView.findViewById(R.id.item_order_list_hoursnum);
            holder.item_order_list_hoursnum.setVisibility(View.INVISIBLE);
            holder.item_order_list_orderstate = (TextView) convertView.findViewById(R.id.item_order_list_orderstate);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        final BillStatis item = list.get(position);
        holder.item_order_list_orderno.setText("账单号："+item.getStatis_no());
        holder.item_order_list_orderdate.setText("金额：￥"+item.getStatis_amount()+"元");
        holder.item_order_list_cycle.setText("周期：" +item.getStatis_start()+ "-"+item.getStatis_end());
        if (item.getStatis_state() == 0) {
            holder.item_order_list_orderstate.setText("已出账");
        } else {
            holder.item_order_list_orderstate.setText("未出账");
        }

        holder.ll_item_order_list.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, BillInfoListActivity.class);
                intent.putExtra("statisId",item.getStatis_id());
                context.startActivity(intent);
            }
        });

        return convertView;
    }

    class ViewHolder {
        private TextView item_order_list_orderno,item_order_list_orderdate,
                item_order_list_cycle,item_order_list_hoursnum,item_order_list_orderstate;
        private LinearLayout ll_item_order_list;
    }

}
